/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FrmDetailClass.java
 *
 * Created on Nov 24, 2011, 11:22:23 PM
 */
package GUI;

import DAO.Connect;
import DatabaseAccess.quanLyLop;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Date;
import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.JOptionPane;

/**
 *
 * @author Dell
 */
public class FrmDetailClass extends javax.swing.JFrame {

   // private boolean chooseActive;
   // private String ID2;
    Connect connect = new Connect();
    Connection conn;
    ResultSet rs;
    PreparedStatement pstmt;
    quanLyLop nhap = new quanLyLop();

    /** Creates new form FrmDetailClass */
    public FrmDetailClass() {
        initComponents();
        filldata();
        GettotalChild();
        ListActive.setModel(new DefaultListModel());
        InitListActiveOfClass(ListActive);
    }

    private void filldata() {
        String strSql = "select ClassID,ClassName,AgeGroupID from tblClass where ClassID=?";
        conn = connect.getConnection();
            try {
                pstmt = conn.prepareStatement(strSql);
               pstmt.setString(1, FrmQuanLyLop.ClassIDD);
                rs = pstmt.executeQuery();
                while (rs.next()) {
                    lbID.setText(rs.getString(1));
                    lbName.setText(rs.getString(2));
                    lbAge.setText(rs.getString(3));
                }
                conn.close();

            } catch (SQLException ex) {
                ex.printStackTrace();
                JOptionPane.showMessageDialog(this, "Error:" + ex.getMessage());
                return;
            }
  }

    public void GettotalChild() {

        try {
            conn = connect.getConnection();
            String strSQL = "select COUNT(ChildID) from tblChild  where ClassID=?";
             pstmt = conn.prepareStatement(strSQL);
            pstmt.setString(1, FrmQuanLyLop.ClassIDD);
            rs = pstmt.executeQuery();
            while (rs.next()) {
                lbtotalchild.setText(rs.getString(1));
            }
            conn.close();

        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    public void InitListActiveOfClass(JList jlist) {
        try {
            conn = connect.getConnection();
            String MySql = "SELECT d.ActiveID,c.ActiveName from tblDetailsActiveClass d "
                    + "join tblActivities c on d.ActiveID=c.ActiveID where ClassID=?";
             pstmt = conn.prepareStatement(MySql);
            pstmt.setString(1, FrmQuanLyLop.ClassIDD);
             rs = pstmt.executeQuery();
            while (rs.next()) {
                String Id = rs.getString(1);
                ((DefaultListModel) ListActive.getModel()).addElement("ID:"+Id +"");
            }
        } catch (SQLException ex) {
            ex.printStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jPanel1 = new javax.swing.JPanel();
        lblClassID = new javax.swing.JLabel();
        lblClassName = new javax.swing.JLabel();
        lblAgeGroupID = new javax.swing.JLabel();
        lblTotalChild = new javax.swing.JLabel();
        lbID = new javax.swing.JLabel();
        lbName = new javax.swing.JLabel();
        lbAge = new javax.swing.JLabel();
        lbtotalchild = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        ListActive = new javax.swing.JList();
        jLabel8 = new javax.swing.JLabel();
        btnClose = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Detail Class");

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 24));
        jLabel1.setForeground(new java.awt.Color(204, 0, 0));
        jLabel1.setText("Detail Class");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblClassID.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblClassID.setForeground(new java.awt.Color(0, 0, 204));
        lblClassID.setText("Class ID :");

        lblClassName.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblClassName.setForeground(new java.awt.Color(0, 0, 204));
        lblClassName.setText("ClassName :");

        lblAgeGroupID.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblAgeGroupID.setForeground(new java.awt.Color(0, 0, 204));
        lblAgeGroupID.setText("AgeGroup ID:");

        lblTotalChild.setFont(new java.awt.Font("Tahoma", 0, 14));
        lblTotalChild.setForeground(new java.awt.Color(0, 0, 204));
        lblTotalChild.setText("TotalChild :");

        lbID.setFont(new java.awt.Font("Tahoma", 0, 14));
        lbID.setForeground(new java.awt.Color(0, 0, 204));
        lbID.setText("a");

        lbName.setFont(new java.awt.Font("Tahoma", 0, 14));
        lbName.setForeground(new java.awt.Color(0, 0, 204));
        lbName.setText("b");

        lbAge.setFont(new java.awt.Font("Tahoma", 0, 14));
        lbAge.setForeground(new java.awt.Color(0, 0, 204));
        lbAge.setText("c");

        lbtotalchild.setFont(new java.awt.Font("Tahoma", 0, 14));
        lbtotalchild.setForeground(new java.awt.Color(0, 0, 204));
        lbtotalchild.setText("d");

        ListActive.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(ListActive);

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabel8.setForeground(new java.awt.Color(0, 0, 204));
        jLabel8.setText("List Active :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(29, 29, 29)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblClassName)
                            .addComponent(lblClassID)
                            .addComponent(lblAgeGroupID))
                        .addGap(80, 80, 80)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lbName, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                            .addComponent(lbID, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)
                            .addComponent(lbAge, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(lblTotalChild)
                            .addComponent(jLabel8))
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(94, 94, 94)
                                .addComponent(lbtotalchild, javax.swing.GroupLayout.DEFAULT_SIZE, 135, Short.MAX_VALUE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblClassID)
                    .addComponent(lbID))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblClassName)
                    .addComponent(lbName))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lblAgeGroupID)
                    .addComponent(lbAge))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbtotalchild)
                    .addComponent(lblTotalChild))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel8)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 168, Short.MAX_VALUE))
                .addContainerGap())
        );

        btnClose.setFont(new java.awt.Font("Tahoma", 0, 12));
        btnClose.setForeground(new java.awt.Color(0, 0, 204));
        btnClose.setIcon(new javax.swing.ImageIcon(getClass().getResource("/image/close2.png"))); // NOI18N
        btnClose.setText("Close");
        btnClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCloseActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(26, 26, 26)
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(133, 133, 133)
                        .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 96, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(32, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(132, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addGap(130, 130, 130))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btnClose, javax.swing.GroupLayout.PREFERRED_SIZE, 31, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18))
        );

        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-416)/2, (screenSize.height-471)/2, 416, 471);
    }// </editor-fold>//GEN-END:initComponents

private void btnCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCloseActionPerformed
    this.dispose();
}//GEN-LAST:event_btnCloseActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrmDetailClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrmDetailClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrmDetailClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrmDetailClass.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new FrmDetailClass().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JList ListActive;
    private javax.swing.JButton btnClose;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel lbAge;
    private javax.swing.JLabel lbID;
    private javax.swing.JLabel lbName;
    private javax.swing.JLabel lblAgeGroupID;
    private javax.swing.JLabel lblClassID;
    private javax.swing.JLabel lblClassName;
    private javax.swing.JLabel lblTotalChild;
    private javax.swing.JLabel lbtotalchild;
    // End of variables declaration//GEN-END:variables
}
